# This file is part of The Vu Toolkit.
#
# The Vu Toolkit is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# The Vu Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with The Vu Toolkit; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Copyright © Zak Fenton 2008
#

# shhh, don't tell anyone we use Gtk
require 'gtk2'

require 'Vu/Gadget'
require 'Vu/Frame'
require 'Vu/GtkFrame'

module Vu
	class Window < GtkFrame
		def initialize (title = "Vu::Window")
			super(Gtk::Window.new)
			
			gtk_peer.app_paintable = true
			gtk_peer.set_colormap(gtk_peer.screen.rgba_colormap)
			
			# close button pressed
			gtk_peer.signal_connect("delete-event") do
				close_button_handle
			end
			gtk_peer.title = title
		end
		
		def window
			self
		end
		
		
		
		@close_button_handler = nil
		
		def close_button_handle
			case @close_button_handler
				when false, nil, :close
					false
				when :ignore
					true
				when :quit
					Gtk.main_quit
					false
				else
					@close_button_handler.call()
			end
		end
		
		# :quit, :close, :ignore or a lambda that returns false to close the
		# window, or true to ignore the event.
		def close_handler= (h)
			@close_button_handler = h
		end
		
		# The title
		def title
			gtk_peer.title
		end
		
		# The title
		def title= (t)
			gtk_peer.title = t
		end
		
		# Move the window
		def move! (x,y)
			gtk_peer.move(x,y)
		end
	end
	
	# Just calls Gtk.main
	def main
		Gtk.main
	end
end


